import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import PageLogin from '../views/PageLogin.vue'
import PageRegister from '../views/PageRegister.vue'
import ClassifiGoods from '../views/ClassifiGoods.vue'
import SearchResults from '../views/SearchResults.vue'
import ProductDetail from '../views/ProductDetail.vue'
import CartconfigView from '../views/CartconfigView.vue' 
import PaymentView from '../views/PaymentView.vue'
import OrdersView from '../views/OrdersView.vue'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: PageLogin
  },
  {
    path: '/register',
    name: 'register',
    component: PageRegister
  },
  {
    path: '/classifigoods',
    name: 'classifigoods',
    component: ClassifiGoods
  },
  {
    path: '/search',
    name: 'SearchResults',
    component: SearchResults,
	props:(route) =>({
		keyword: route.query.keyword,
		results: route.params.results
	})
  },
  {
      path: '/product/:product_id',  // 动态路由参数
      name: 'ProductDetail',
      component: ProductDetail,
      props: true  // 将路由参数作为props传递给组件
    },
	 {
	    path: '/cart',
	    name: 'cart', 
	    component: CartconfigView 
	  },
	{
	  path: '/payment',
	  name: 'payment',
	  component: PaymentView,
	   meta: {
	      requiresAuth: true // 如果需要登录才能访问
	    }
	},
	{
	  path: '/orders',
	  name: 'orders',
	  component: OrdersView
	},
]

const router = new VueRouter({
  routes
})

export default router
